<?  layout("../layout/default.html") { ?>
<script src="${root}/Static/js/jquery.form.js"></script>
<script>
var ajaxSubmit = function(){
	$('#AjaxForm').ajaxSubmit({  
	    dataType: "json",  
	    beforeSubmit:function(_arr,_from,_options){
	    	var _type = $.grep( _arr, function(n,i){
		    	return n.name=='sysres.type';
			});
			if(_type.length==1) _type = _type[0].value;
	    	var _ak = $.grep( _arr, function(n,i){
		    	return n.name=='sysres.ak';
			});
			if(_ak.length==1) _ak = _ak[0].value;
			if(_type=="1"&&_ak==""){
				alert("请选择ActionKey");
	    		return false;
			}else if(_type=="0"&&_ak!=""){
				alert("请勿选择ActionKey");
	    		return false;
			}
				return true;
	    },
	    success: function(json) {
	    	if (json.success) {
				var treeObj = parent.$.fn.zTree.getZTreeObj('treex');				
				<? if(@data.isNew()==false){ ?>
				var node = treeObj.getNodeByParam("id", json.data.id, null);
				if(node!=null){	
					node.name = json.data.name
					treeObj.updateNode(node);
				}
				<?}else{ ?>				
				var node = treeObj.getNodeByParam("id", json.data.pid, null);
				treeObj.addNodes(node, json.data);
				<?} ?>
				parent.$('.dialogx-mask').remove();
				parent.$('.dialogx-win').remove();
	    	};
	            isSubmit = false;  
	        obj.removeAttr("disabled");  
	        obj.attr({"value":"提交"});  
        }   
	}); 
	return false; 
}
</script>
<div class="admin-panel">
	<div class="tab">
		<div class="tab-head">
			<strong><? if(@data.isNew()){ ?>添加<? }else{ ?>编辑<?} ?></strong>
			<!-- <span class="tab-more"><a href="javascript:history.go(-1)" class="button  button-little bg-blue  icon-step-backward"> 返回</a></span> -->
			<ul class="tab-nav">
			  <li class="active"><a href="#tab-set">信息</a></li>
			</ul>
		</div>
		<div class="tab-body">
			<div class="tab-panel active" id="tab-set">
				<form method="post" class="form-x" action="" onsubmit="return ajaxSubmit();" id="AjaxForm">
					<input type="hidden" id="sysres_pid" name="sysres.pid"  value="${data.pid!"0"}"/>
									
					<div class="form-group">
						<div class="label"><label for="sitename">名称</label></div>
						<div class="field">
						<input type="text" class="input" id="sysres_cname" name="sysres.cname" size="50" placeholder="请填写名称" data-validate="required:请填写名称" value="${data.cname!""}"/>
						</div>
					</div>
					
					<div class="form-group">
						<div class="label"><label for="sitename">权限识别码</label></div>
						<div class="field">
							<div class="input-group">
							<span class="addon strong"><strong>${data.parent_code!"根节点"}：</strong></span>
							<input type="text" class="input" id="sysres_code" name="sysres.code" size="50" placeholder="请填写权限识别码" data-validate="required:请填写权限识别码,english:只能填写英文" value="${data.code!""}"/>
							</div>
						</div>
					</div>
					
					<div class="form-group">
						<div class="label"><label for="sitename">描述</label></div>
						<div class="field">
						<input type="text" class="input" id="sysres_des" name="sysres.des" size="200" placeholder="请填写描述" data-validate="" value="${data.des!""}"/>
						</div>
					</div>
					<div class="form-group">
						<div class="label"><label for="sitename">类型</label></div>
						<div class="field">
						<div class="button-group button-group-small radio">
							<label class="button" id="sysres_type_0"><input name="sysres.type" value="0"  type="radio"><span class="icon icon-check"></span> 无</label>
							<label class="button" id="sysres_type_1"><input name="sysres.type" value="1" type="radio"><span class="icon icon-check"></span> ActionKey</label>
						</div>
						<script>
							$("#sysres_type_${data.type!0}").addClass('active').children('input').attr('checked',true);
						</script>
						</div>
					</div>
					<div class="form-group">
						<div class="label"><label for="sitename">actionKey</label></div>
						<div class="field">
							<select class="input" id="sysres_ak" name="sysres.ak">
								<option value="">请选择actionKey</option>
								<? for(ak in aks){?>								
								<option>${ak}</option>
								<?}?>
							</select>
							<script>
								$("#sysres_ak").val('${data.ak!""}');
							</script>
						</div>
					</div>
					
					<div class="form-group">
						<div class="label"><label for="sitename">排序</label></div>
						<div class="field">
						<input type="text" class="input" id="sysres_seq" name="sysres.seq" size="11" placeholder="排序" data-validate="" value="${data.seq!"10"}"/>
						</div>
					</div>
					
					
					
				<div class="form-button"><button class="button bg-main" type="submit" >提交</button></div>
			    </form>
			</div>
		</div>
	</div>
</div>
<?  } ?>		
<script>
	
</script>